<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page language="java" %>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>

<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <meta HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
   <meta HTTP-EQUIV="EXPIRES" CONTENT="0">
   <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
   
   <script>
      // Retrieves the list of waste types for a searched waste type desc
      function search()
      {
         fnForward('wasteType.shs', 'initWasteTypes');
      }

      // Retrieves the details for a selected waste type
      function view(wasteTypeId)
      {
         Form.wasteTypeId.value = wasteTypeId;
         fnForward('wasteType.shs', 'getWasteDetails');
      }

      // Brings up the screen to add a new waste type
      function add() 
      {
         fnForward("wasteType.shs", "addWasteType");
      }

      // Deletes selected waste types
      function fnDelete() 
      {
         fnForward("wasteType.shs", "delWasteTypes");
      }
   </script>
</head>
<body class="textInputNormal_12">

   <form name="wasteTypeForm" method="post">
      <input type="hidden" name="impl"/>
      <input type="hidden" name="wasteTypeId"/>
      <script>
         var pgName = "wasteType";
         var Form = document.wasteTypeForm;
      </script>
      <div>
         Search for waste type: 
         <input type="text" name="wasteTypeSrch" class="textInputNormal_12"
            value="${wasteTypeForm.wasteTypeSrch}"/>
         &nbsp;
         <input type="submit" class="bttn" value=" Go " onclick="search()"/>
         <input type="button" class="bttn" value="  Add  " onclick="add()" id="addBttn"/>
      </div>
      
      <c:choose>
         <c:when test="${success != null}">
            <div class="successDiv" style="margin-top: 10px;">
               ${success}
            </div>
         </c:when>
         <c:when test="${failure != null}">
            <div class="errDiv" style="margin-top: 10px;">
               ${failure}
            </div>
         </c:when>
      </c:choose>
      
      <c:choose>
         <c:when test="${wasteTypeList != null && not empty(wasteTypeList)}">
            <div style="margin-top: 10px;">
               The different waste types entered into the system are listed below:
            </div>
            <div class="scrollBox" style="width: 70%">               
               <div class="mainListing">
                  <table width="100%" class="listingTbl">
                     <tr class="header">
                        <td width="3%">
                           <input type="checkbox" name="chkMain" 
                              onclick="chkAll('chkWasteTypeId', this)"/>
                        </td>
                        <td width="40%">
                           Aggregate Waste Description
                        </td>
                        <td width="40%">
                           Waste Type Description
                        </td>
                        <td>
                           Avg. Market Rate
                        </td>
                     </tr>
                     <c:set var="prevAggrWasteType" value=""/>
                     <c:set value="evenRow" var="rowColour"/>
                     <%-- 
                        The following logic allows for colouring the rows belonging to 
                        a particular type of aggregate waste type a different colour
                     --%>
                     <c:forEach items="${wasteTypeList}" var="wasteType">
                        <c:if test="${prevAggrWasteType != wasteType.aggrWasteDesc}">
                           <c:choose>
                              <c:when test="${rowColour == 'evenRow'}">
                                 <c:set value="oddRow" var="rowColour"/>
                              </c:when>
                              <c:otherwise>
                                 <c:set value="evenRow" var="rowColour"/>
                              </c:otherwise>
                           </c:choose>
                        </c:if>
                        <tr class="${rowColour}">
                           <td width="3%">
                              <input type="checkbox" name="chkWasteTypeId" value="${wasteType.wasteId}"/>
                           </td>
                           <td width="41%">
                              <%-- 
                                 Only display the aggregate waste type if a new one is
                                 encountered.
                              --%>
                              <c:if test="${prevAggrWasteType != wasteType.aggrWasteDesc}"> 
                                 ${wasteType.aggrWasteDesc}
                                 <c:set var="prevAggrWasteType" value="${wasteType.aggrWasteDesc}"/>
                              </c:if>
                           </td>
                           <td width="41%">
                              <a href="#" class="gLink" onclick="view('${wasteType.wasteId}')"> 
                                 ${wasteType.wasteDesc}
                              </a>   
                           </td>
                           <td>
                              ${wasteType.avgMrktRate}
                           </td>
                        </tr>
                     </c:forEach>
                  </table>
               </div>
            </div>
            <input type="button" class="bttn" value="Delete" onclick="fnDelete()" id="delBttn"/>
         </c:when>
         <c:otherwise>
            <div class="errDiv" style="margin-top: 15px;">
               No List present
            </div>
         </c:otherwise>
      </c:choose>
   </form>

</body>
</html>